package com.controller;

import com.config.RedisCache;
import com.entity.Admin;
import com.entity.ums.AdminLoginLog;
import com.service.ReceiveAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

@Controller
public class ReceiveAddressController {
    public ReceiveAddressController() {
        System.out.println("asfdfsfd");
    }

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private ReceiveAddressService receiveAddressService;

//    @RequestMapping(value = "index.html")
//    public String index() {
//        return "index";
//    }

//    @ResponseBody
//    @GetMapping(value = "hello/{id}")
//    public Map<String, Object> hello(@PathVariable Integer id) {
//        return receiveAddressService.getReceiveOrder(id);
//    }

    @ResponseBody
    @GetMapping(value = "hello")
    public List<Map<String, Object>> hello() {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Object value = null;
        try {
            value = valueOperations.get("abc");
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (value == null) {
            valueOperations.set("abc", "asfdsfad");
        } else {
            System.out.println(value);
        }


        return receiveAddressService.getReceiveAddressList();
    }

    @ResponseBody
    @GetMapping("hellos")
    public List<Admin> hellos() {
        return receiveAddressService.getList();
    }

    @GetMapping("/admin/{id}")
    @ResponseBody
    public Admin getAdmin(@PathVariable Integer id) {
        return receiveAddressService.getAdminAndLog(id);
    }
    @GetMapping("/adminLog/{admin_id}")
    @ResponseBody
    public List<AdminLoginLog> getadminLog(@PathVariable Integer admin_id) {
        try {
            return receiveAddressService.getAdminLoginList(admin_id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
